package duotai;

/**
 *  土地类
 */
public class Land {
    /*
    新增Land类  添加记录土地是否空闲的变量idle 新增种植作物的方法plant()
        编写种植苹果树的方法
        编写种植玉米的方法

        plant: 植物, 种植
     */
// 土地是否空闲的变量idle boolean 默认是flase
    private boolean idle=true;

    private Crop crop;
    public Crop getCrop(int choose) {
        switch (choose) {
            case 1:
                crop = new AppleTree();
                crop.setName("苹果树");
                return crop;
            case 2:
                return  new Corn();
            case 3:
                return new Pear();
                default:
                    System.out.println("输入错误");
                    return null;
        }

    }



    public void plant(Crop a) {
        if (idle) {// 空闲状态
            if (a instanceof AppleTree) {
                AppleTree appleTree = (AppleTree) a;
                System.out.println("已经种植了苹果树!");
            } else if (a instanceof Corn) {
                Corn corn = (Corn) a;
                System.out.println("已经种植了玉米!");
            }
            this.crop = a; // AppleTree appleTree= new AppleTree();
            crop.print();
            idle = false;// 非空闲状态
        } else {
            System.out.println("土地不空闲，无法种植苹果树!");
        }
    }

    public void printCrop() {
        if(crop!=null) {
            crop.print();
        }else{
            System.out.println("土地空闲,植物还没有种植");
        }


    }

    public void useuseCrop(){
        if(crop instanceof AppleTree){
            AppleTree appleTree = (AppleTree) crop;
            String brand = appleTree.getBrand();
           System.out.println(brand);
        }else if(crop instanceof Corn){
            Corn corn = (Corn) crop;
            double cost = corn.getHarvestCost();
            System.out.println(cost);
        }
    }



}
